package io.lvdaxian.handwriting.sort.entity;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public class User implements Comparable<User>, Serializable {
  
  private final Integer age;
  
  public User(Integer age) {
    this.age = age;
  }
  
  public Integer getAge() {
    return age;
  }
  
  @Override
  public String toString() {
    return "User{" +
        "age=" + age +
        '}';
  }
  
  @Override
  public int compareTo(User o) {
    return this.age - o.getAge();
  }
  
  public static void main(String[] args) {
    List<User> list = new ArrayList<>();
    list.add(new User(1));
    list.add(new User(2));
    
    Collections.sort(list);
    
    list.forEach(System.out::println);
  }
}
